<template>
  <el-dialog
    :title="title"
    width="38%"
    :visible="dialogflag"
    :before-close="handleClose"
    :close-on-click-modal="false"
    :destroy-on-close="true"
  >
    <el-form
      ref="elForm"
      :model="formData"
      :rules="rules"
      size="medium"
      label-width="100px"
      label-position="right"
      :style="{ width: '100%' }"
      class="dialogForm"
    >
      <!-- 第一行 -->
      <el-form-item label="字段名" prop="fieldName">
        <el-input
          :disabled="inputStatus == 1 && title == '编辑'"
          v-model="formData.fieldName"
          placeholder="请输入字段名"
          clearable
          :style="{ width: '100%' }"
        ></el-input>
      </el-form-item>
      <!-- 第二行 -->
      <el-form-item label="字段类型" prop="fieldType">
        <el-select
          :disabled="inputStatus == 1 && title == '编辑'"
          v-model="formData.fieldType"
          placeholder="请选择字段类型"
          clearable
          :style="{ width: '100%' }"
          @change="changedSelect"
        >
          <el-option
            v-for="(item, index) in field103Options"
            :key="index"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <!-- 第三行 -->
      <el-form-item label="字段标识" prop="fieldLabel">
        <el-input
          :disabled="inputStatus == 1 && title == '编辑'"
          v-model="formData.fieldLabel"
          placeholder="请输入字段标识"
          maxlength="255"
          clearable
          :style="{ width: '100%' }"
          show-word-limit
        >
        </el-input>
      </el-form-item>
      <!-- 第四行 -->
      <el-form-item
        label="长度"
        prop="length"
        v-if="!(formData.fieldType == 'Dynamic Link')"
      >
        <el-input
          v-model="formData.length"
          placeholder="请输入长度"
          clearable
          oninput="value=value.replace(/[^\d]/g,'')"
          :style="{ width: '100%' }"
          :disabled="
            !(
              formData.fieldType == 'Int' ||
              formData.fieldType == 'String' ||
              formData.fieldType == 'Date' ||
              formData.fieldType == 'Password' ||
              formData.fieldType == 'Float' ||
              formData.fieldType == 'Double'
            )
          "
        ></el-input>
      </el-form-item>
      <!-- 第五行 -->
      <el-form-item
        label="精度"
        prop="precision"
        v-if="!(formData.fieldType == 'Dynamic Link')"
      >
        <el-select
          v-model="formData.precision"
          placeholder="请选择精度"
          clearable
          :style="{ width: '100%' }"
          :disabled="
            !(
              formData.fieldType == 'Currency' ||
              formData.fieldType == 'Float' ||
              formData.fieldType == 'Double'
            )
          "
        >
          <el-option
            v-for="(item, index) in precisionList"
            :key="index"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <div style="margin: -14px 100px 15px; font-size: 12px; color: #bfc1c5">
        注：字段类型为“Float”和“Currency”类型设置精度
      </div>
      <!-- 第六行 多选框 -->

      <el-form-item v-if="inputStatus == 1 && title == '编辑'">
        <el-checkbox-group v-model="listValueCheckInfo" size="medium">
          <el-checkbox
            v-for="(item, index) in checkboxOptions"
            :key="index"
            :label="item.value"
            :disabled="item.disabled"
            >{{ item.label }}</el-checkbox
          >
        </el-checkbox-group>
        <!-- <el-checkbox-group v-model="listValueCheckInfo" size="medium" v-else>
          <el-checkbox
            v-for="(item, index) in OthercheckboxOptions"
            :key="index"
            :label="item.value"
            :disabled="item.disabled"
            >{{ item.label }}</el-checkbox
          >
        </el-checkbox-group> -->
      </el-form-item>

      <el-form-item v-else>
        <el-checkbox-group v-model="formData.listValueCheck" size="medium">
          <el-checkbox
            v-for="(item, index) in checkboxOptions"
            :key="index"
            :label="item.value"
            :disabled="item.disabled"
            >{{ item.label }}</el-checkbox
          >
        </el-checkbox-group>

        <!-- <el-checkbox-group v-model="listValueCheckInfo" size="medium" v-else>
          <el-checkbox
            v-for="(item, index) in OthercheckboxOptions"
            :key="index"
            :label="item.value"
            :disabled="item.disabled"
            >{{ item.label }}</el-checkbox
          >
        </el-checkbox-group> -->
      </el-form-item>
      <!-- 第七行 -->
      <el-form-item
        label="录入方式"
        prop="entryMethodList"
        v-if="this.formData.fieldType == 'Datetime'"
        class="newcheckout"
      >
        <el-radio-group v-model="entryMethodList">
          <el-radio :label="0">手动录入</el-radio>
          <el-radio :label="1">系统时间</el-radio>
        </el-radio-group>
      </el-form-item>
      <!-- 第八行 -->
      <el-form-item label="格式" v-if="this.entryMethodList == 1">
        <el-select
          v-model="entryMethodModel"
          placeholder="请选择格式"
          clearable
          :style="{ width: '100%' }"
          @change="changedFormat"
        >
          <el-option
            v-for="item in formatList"
            :key="item.label"
            :label="item.value"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <!-- 第七行 -->
      <el-form-item
        label="默认值"
        prop="defaultValue"
        v-if="!(formData.fieldType == 'Dynamic Link')"
      >
        <el-input
          v-model="formData.defaultValue"
          type="textarea"
          placeholder="请输入默认值"
          :autosize="{ minRows: 3, maxRows: 3 }"
          :style="{ width: '100%' }"
          :disabled="
            this.formData.fieldType === 'Link' ||
            this.formData.fieldType === 'Table' ||
            this.formData.fieldType === 'Select' ||
            this.formData.fieldType === 'Table MultiSelect'
          "
        ></el-input>
      </el-form-item>
      <!-- 第八行 -->
      <el-form-item
        label="从其他元数据中获取字段值"
        prop="firstValueSelect"
        v-if="
          !(
            formData.fieldType == 'Dynamic Link' ||
            this.formData.fieldType == 'Datetime'
          )
        "
      >
        <el-select
          v-model="firstValueSelect"
          @change="selectChanged"
          placeholder="请选择元数据"
          clearable
          :style="{ width: '100%' }"
          :disabled="this.formData.fieldType !== 'Link'"
        >
          <el-option
            v-for="item in OtherList"
            :key="item.id"
            :label="item.label"
            :value="item.id"
            class="firstValueStyle"
          >
            <span class="labelStyle">{{ item.label }}</span>
            <span class="modelnameStyle">{{ item.moduleName }}</span>
            <span class="nameStyle">{{ item.name }}</span>
          </el-option>
        </el-select>
      </el-form-item>
      <!-- 第九行 -->
      <el-form-item
        prop="fetchFrom"
        style="margin-top: -50px"
        v-if="
          !(
            formData.fieldType == 'Dynamic Link' ||
            this.formData.fieldType == 'Datetime'
          )
        "
      >
        <el-select
          v-model="formData.fetchFrom"
          placeholder="请继续选择"
          clearable
          :disabled="!firstValueSelect"
          :style="{ width: '100%' }"
        >
          <el-option
            v-for="(item, index) in ContinueSelection"
            :key="index"
            :label="item.fieldLabel"
            :value="item.fieldLabel"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item prop="fetchIfEmpty" v-if="formData.fetchFrom">
        <el-checkbox v-model="formData.fetchIfEmpty"
          >仅在没有输入该值的时候获取</el-checkbox
        >
      </el-form-item>
      <!-- 第五行 -->
      <el-row
        v-if="this.formData.fieldType === 'Select'"
        style="margin-bottom: 20px"
      >
        <!-- 动态添加/删除输入框 -->
        <el-col :span="4"> <div style="margin-left: 50px">选择</div></el-col>
        <el-col :span="20"
          ><div class="selectBox">
            <el-form-item
              v-for="(item, index) in formData.select"
              :key="item.index"
              :prop="'select.' + index + '.value'"
              :rules="{
                required: true,
                message: '内容不能为空',
                trigger: 'blur',
              }"
            >
              <div>
                <el-input
                  v-model="item.value"
                  :style="{ width: '92%' }"
                ></el-input>
                <i
                  class="el-icon-remove-outline inconstyle"
                  @click.prevent="remove(item)"
                ></i>
              </div>
            </el-form-item>
            <i
              class="el-icon-circle-plus-outline inconstyle addinconstyle"
              @click="add"
              >添加</i
            >
          </div></el-col
        >
      </el-row>
      <!-- 如果是Dynamic Link的情况下---关联字段 -->
      <el-form-item
        label="关联字段"
        prop="dlinkListInfo"
        v-if="formData.fieldType == 'Dynamic Link'"
      >
        <el-select
          v-model="DlinkListInfo"
          placeholder="选择元数据字段"
          clearable
          @change="changeDlink"
          :style="{ width: '100%' }"
        >
          <el-option
            v-for="item in DlinkList"
            :key="item.fieldLabel"
            :label="item.fieldLabel"
            :value="item.fieldLabel"
            class="firstValueStyle"
          >
            <span class="labelStyle">{{ item.fieldLabel }}</span>
            <span class="nameStyle">{{ item.fieldName }}</span>
          </el-option>
        </el-select>
      </el-form-item>
      <!-- 第十行 -->
      <el-form-item label="描述" prop="description">
        <el-input
          v-model="formData.description"
          placeholder="请输入描述"
          :autosize="{ minRows: 3, maxRows: 3 }"
          type="textarea"
          :style="{ width: '100%' }"
        ></el-input>
      </el-form-item>
      <el-row
        v-if="
          this.formData.fieldType === 'Link' ||
          this.formData.fieldType === 'Table' ||
          this.formData.fieldType === 'Table MultiSelect'
        "
      >
        <el-form-item label="选择" prop="linkOrTable">
          <el-select
            v-model="linkOrTableInfo"
            @change="selectChoose"
            placeholder="请选择元数据"
            clearable
            :style="{ width: '100%' }"
            :disabled="this.formData.fieldType === 'Link'"
          >
            <el-option
              v-for="item in OtherList"
              :key="item.id"
              :label="item.label"
              :value="item.label"
              class="firstValueStyle"
            >
              <span class="labelStyle">{{ item.label }}</span>
              <span class="modelnameStyle">{{ item.moduleName }}</span>
              <span class="nameStyle">{{ item.name }}</span>
            </el-option>
          </el-select>
        </el-form-item>
      </el-row>
    </el-form>
    <div class="dialog-footer">
      <el-button size="medium" @click="handleClose" class="bootonclose"
        >取 消</el-button
      >
      <el-button
        size="medium"
        type="primary"
        @click="handleOk"
        class="bootonok"
      >
        保存
      </el-button>
    </div>
    <img
      src="../../../../../assets/images/lodingBar.png"
      alt=""
      class="lodingBar"
    />
  </el-dialog>
</template>

<script>
import {
  getMetadataFieldNameList,
  getMetadataList,
  getPrecisionNum,
  getFieldType,
  getTimeFormatEnums,
} from "@/api/metadata/metadata";
export default {
  name: "Logdialog",
  props: {
    dialogflag: {
      type: Boolean,
    },
    dataObj: {
      type: Object,
    },
    chooseDataList: {
      type: Array,
    },
    metadataId: {
      type: String,
    },
    inputStatus: {
      type: String,
    },
    tableData: {
      type: Array,
    },
  },
  data() {
    const validatorName = (rule, value, callback) => {
      // var reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[A-Za-z_][A-Za-z_0-9]{0,}$/;
      var reg = /^(?!_)[a-zA-Z0-9_\u4e00-\u9fa5]+$/;
      var regnum = /^[0-9].*$/;
      if (!value) {
        return callback("请输入元数据标识");
      } else {
        // setTimeout(() => {
        if (!reg.test(value)) {
          callback(
            new Error("只含有汉字、数字、字母、下划线,不能以下划线开头")
          );
        } else if (regnum.test(value)) {
          callback(new Error("不能以数字开头!"));
        } else {
          callback();
        }
        // }, 100);
      }
    };
    const validatorLabel = (rule, value, callback) => {
      // var reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[A-Za-z_][A-Za-z_0-9]{0,}$/;
      var reg = /^[a-zA-Z0-9_]+$/;
      var regnum = /^[0-9].*$/;
      var regline = /^([a-zA-Z])[a-z0-9]*$/i;
      // var regNum=/^.{1,255}$/;
      if (!value) {
        return callback("请输入字段标识");
      } else {
        // setTimeout(() => {
        if (!reg.test(value)) {
          callback(new Error("只能由字母、数字和下划线组成 "));
        } else if (regnum.test(value)) {
          callback(new Error("不能以数字开头!"));
        } else if (!regline.test(value)) {
          callback(new Error("只能由字母开头!"));
        } else {
          callback();
        }
        // }, 100);
      }
    };
    //如果是Dlink的情况下validatorDlink进项校验
    const validatorDlink = (rule, value, callback) => {
      console.log(value, "rule, value, callback");
      if (!value) {
        //做一下如果是DLink的情况下，DlinkList是空的时候的弹框
        if (this.DlinkList.length === 0) {
          return this.$message.error("请先创建Select类型字段");
        }
        if(this.DlinkListInfo){
          return  callback();
        }
        callback(new Error("请选择关联字段!"));
      }else {
          callback();
        }
    };
    return {
      formData: {
        fieldName: "",
        fieldType: "", //选择 1--select 2-Link  3-Table 4-Table MultiSelect 5-Dlink
        fieldLabel: "",
        dlinkListInfo: "",
        length: "",
        metadataName: "",
        precision: "", //精度
        listValueCheck: [],
        defaultValue: "",
        fetchFrom: "",
        fetchIfEmpty: false,
        description: "",
        choose: "",
        linkOrTable: "",
        dataType: null, //录入方式
        format: "", //格式
        select: [
          {
            value: "",
          },
        ],
      },
      linkOrTableInfo: "", //如果是link/Table的时候穿这个id;
      //从其他元数据中获取字段值 第一个值
      firstValueSelect: "",
      OtherList: [],
      rules: {
        fieldName: [
          {
            required: true,
            validator: validatorName,
            trigger: "blur",
          },
        ],
        fieldType: [
          {
            required: true,
            message: "请输入元数据标识",
            trigger: "change",
          },
        ],
        dlinkListInfo: [
          {
            required: true,
            validator: validatorDlink,
            trigger: "change",
          },
        ],
        fieldLabel: [
          {
            required: true,
            validator: validatorLabel,
            trigger: "blur",
          },
        ],
      },
      //字段类型选择列
      field103Options: [],
      //录入方式
      entryMethodList: 0,
      //录入的格式
      entryMethodModel: "",
      //请求回来的格式list
      formatList: [],
      //多选框选项列
      checkboxOptions: [
        {
          label: "必填",
          value: "notNull",
        },
        {
          label: "唯一",
          value: "isUnique",
        },
        {
          label: "关键字搜索",
          value: "inGlobalSearch",
        },
        {
          label: "非负数",
          value: "nonNegative",
        },
      ],
      //如果是Dlink的话拿到上一层的数据
      DlinkList: [],
      //如果是DLink的话，选中的值
      DlinkListInfo:'',
      //如果是Dlink的时候的值
      // dlinkListInfo:'',
      // OthercheckboxOptions:[
      //     {
      //     label: "必填",
      //     value: "notNull",
      //   },
      //   {
      //     label: "唯一",
      //     value: "isUnique",
      //   },
      //   {
      //     label: "关键字搜索",
      //     value: "inGlobalSearch",
      //   },
      // ],
      precisionList: [],
      dialogVisible: false,
      title: "",
      //继续输入
      ContinueSelection: [],
      //编辑的时候的checkList
      listValueCheckInfo: [],
      //字段名是否重复
      formDataisShowOne: 0, //0--没有重复  1--有重复
      //字段标识是否重复
      formDataisShowTwo: 0, //0--没有重复  1--有重复
    };
  },
  mounted() {
    //从其他元数据中获取字段值
    this.getOtherInfo();
    console.log(
      this.tableData,
      this.dataObj,
      this.dataObj.index,
      this.inputStatus,
      "子组件接收的数据"
    );
    console.log(this.tableData, "  this.tableData");
    this.tableData.map((item) => {
      if (item.fieldType == "Select") {
        this.DlinkList.push({
          fieldLabel: item.fieldLabel,
          fieldName: item.fieldName,
        });
      }
    });
    console.log(this.DlinkList, "  this.DlinkList.");
    if (this.dataObj.flag === "add") {
      //新增/编辑元数据——添加
      this.title = "添加";
    } else {
      //新增/编辑元数据——编辑
      this.title = "编辑";
      let objInfo = this.dataObj.row;
      if (objInfo.fieldType == "Select") {
        objInfo.chooseData = "";
      }
      if (this.inputStatus == 1) {
        //编辑元数据- 编辑弹框
        if (objInfo.notNull) {
          this.listValueCheckInfo.push("notNull");
        }
        if (objInfo.inGlobalSearch) {
          this.listValueCheckInfo.push("inGlobalSearch");
        }
        if (objInfo.hideDays) {
          this.listValueCheckInfo.push("hideDays");
        }
        if (objInfo.hideSeconds) {
          this.listValueCheckInfo.push("hideSeconds");
        }
        if (objInfo.nonNegative) {
          this.listValueCheckInfo.push("nonNegative");
        }
        if (objInfo.isAutoIncrement) {
          this.listValueCheckInfo.push("isAutoIncrement");
        }
        if (objInfo.isUnique) {
          this.listValueCheckInfo.push("isUnique");
        }
        // this.firstValueSelect = objInfo.metadataName;
        this.formData = objInfo;
        if (objInfo.fieldType == "Select") {
          this.formData.select = this.chooseDataList[this.dataObj.index - 1];
        } else if (
          objInfo.fieldType == "Table" ||
          objInfo.fieldType == "Table MultiSelect"
        ) {
          this.$nextTick(function () {
            this.linkOrTableInfo =
              this.chooseDataList[this.dataObj.index - 1][0].metadataLabel;
          });
        } else if (objInfo.fieldType == "Link") {
          this.$nextTick(function () {
            this.firstValueSelect =
              this.chooseDataList[this.dataObj.index - 1][0].metadataLabel;
            this.formData.fetchFrom =
              this.chooseDataList[this.dataObj.index - 1][0].metadataFieldLabel;
          });
        } else if (objInfo.fieldType == "Dynamic Link") {
          this.$nextTick(function () {
            this.DlinkListInfo =
              this.chooseDataList[this.dataObj.index - 1][0].metadataFieldLabel;
          });
        } else {
          this.$nextTick(function () {
            this.firstValueSelect = this.formData.metadataName;
          });
          // this.linkOrTableInfo = this.formData.linkOrTable;
        }

        // console.log(this.formData, "333333333");
      } else {
        //新增元数据- 编辑弹框
        this.formData = objInfo;
        this.formData.select = objInfo.select;
        this.firstValueSelect = objInfo.metadataName;
        this.linkOrTableInfo = objInfo.linkOrTable;
        // console.log(this.linkOrTableInfo,'this.linkOrTableInfo');
      }
      if (objInfo.fieldType == "Datetime" && objInfo.chooseData) {
        this.entryMethodList = 1;
        this.entryMethodModel = objInfo.chooseData;
      }
      console.log(this.formData, "this.formData");
    }
    this.changedSelect();
    //获取精度
    this.getPrecision();
    //获取字段类型枚举
    this.getFieldTypeName();
    //获取时间格式枚举
    this.getFormat();
  },
  methods: {
    //如果是Dlink的时候
    changeDlink(val){
         this.formData.dlinkListInfo=val;
    },
    changedSelect(val) {
      if (val) {
        this.firstValueSelect = "";
        this.formData.fetchFrom = "";
        this.linkOrTableInfo = "";
      }
      console.log(this.formData.fieldType, this.title, "formData.fieldType");
      if (this.formData.fieldType == "Int") {
        this.checkboxOptions = [
          {
            label: "必填",
            value: "notNull",
          },
          {
            label: "唯一",
            value: "isUnique",
          },
          {
            label: "关键字搜索",
            value: "inGlobalSearch",
          },
          {
            label: "非负数",
            value: "nonNegative",
          },
          {
            label: "自增",
            disabled:
              this.title == "添加" || this.inputStatus == 2 ? false : true,
            value: "isAutoIncrement",
          },
        ];
      } else if (
        this.formData.fieldType == "Float" ||
        this.formData.fieldType == "Double" ||
        this.formData.fieldType == "Currency"
      ) {
        this.checkboxOptions = [
          {
            label: "必填",
            value: "notNull",
          },
          {
            label: "唯一",
            value: "isUnique",
          },
          {
            label: "关键字搜索",
            value: "inGlobalSearch",
          },
          {
            label: "非负数",
            value: "nonNegative",
          },
        ];
      } else if (
        this.formData.fieldType == "String" ||
        this.formData.fieldType == "Date"
      ) {
        this.checkboxOptions = [
          {
            label: "必填",
            value: "notNull",
          },
          {
            label: "唯一",
            value: "isUnique",
          },
          {
            label: "关键字搜索",
            value: "inGlobalSearch",
          },
        ];
      } else if (
        this.formData.fieldType == "Boolean" ||
        this.formData.fieldType == "Datetime" ||
        this.formData.fieldType == "Link" ||
        this.formData.fieldType == "Long Text" ||
        this.formData.fieldType == "Percent" ||
        this.formData.fieldType == "Select" ||
        this.formData.fieldType == "Samll Text" ||
        this.formData.fieldType == "Time"
      ) {
        //没有非负数
        this.checkboxOptions = [
          {
            label: "必填",
            value: "notNull",
          },
          {
            label: "唯一",
            value: "isUnique",
          },
          {
            label: "关键字搜索",
            value: "inGlobalSearch",
          },
        ];
      } else if (
        this.formData.fieldType == "Attach" ||
        this.formData.fieldType == "Attach Image" ||
        this.formData.fieldType == "Rating" ||
        this.formData.fieldType == "Table" ||
        this.formData.fieldType == "Table MultiSelect" ||
        this.formData.fieldType == "Button" ||
        this.formData.fieldType == "Text Editor" ||
        this.formData.fieldType == "Signature"
      ) {
        //没有关键字搜索、非负数
        this.checkboxOptions = [
          {
            label: "必填",
            value: "notNull",
          },
          {
            label: "唯一",
            value: "isUnique",
          },
        ];
      } else if (this.formData.fieldType == "Duration") {
        //没有非负数 有隐藏天 隐藏秒
        this.checkboxOptions = [
          {
            label: "必填",
            value: "notNull",
          },
          {
            label: "唯一",
            value: "isUnique",
          },
          {
            label: "关键字搜索",
            value: "inGlobalSearch",
          },
          {
            label: "隐藏天",
            value: "hideDays",
          },
          {
            label: "隐藏秒",
            value: "hideSeconds",
          },
        ];
      } else if (this.formData.fieldType == "Password") {
        //灭有关键字、非负数
        this.checkboxOptions = [
          {
            label: "必填",
            value: "notNull",
          },
          {
            label: "唯一",
            value: "isUnique",
          },
        ];
      } else if (this.formData.fieldType == "Dynamic Link") {
        //灭有关键字、非负数
        this.checkboxOptions = [
          {
            label: "必填",
            value: "notNull",
          },
          {
            label: "唯一",
            value: "isUnique",
          },
          {
            label: "关键字搜索",
            value: "inGlobalSearch",
          },
        ];
      }
    },
    changedFormat(val) {
      this.formData.chooseData = val;
      console.log(val, this.formData, "changedFormat");
    },
    getFormat() {
      getTimeFormatEnums()
        .then((response) => {
          this.formatList = response.data;
        })
        .catch((err) => {
          console.log(err);
          // this.$message.error(err.message);
        });
    },
    handleAdd() {
      if (this.formData.fieldType == "Select") {
        this.formData.choose = 1;
      } else if (this.formData.fieldType == "Link") {
        this.formData.choose = 2;
      } else if (this.formData.fieldType == "Table") {
        this.formData.choose = 3;
      } else if (this.formData.fieldType == "Table MultiSelect") {
        this.formData.choose = 4;
      } else if (this.formData.fieldType == "Dynamic Link") {
        this.formData.choose = 5;
      } else {
        this.formData.choose = 0;
      }
      //如果是编辑元数据-编辑弹框的时候
      if (this.inputStatus == 1) {
        if (this.title == "编辑") {
          this.formData.listValueCheck = this.listValueCheckInfo;
        }
      }
      this.formData.linkOrTable = this.linkOrTableInfo;
      this.formData.dlinkListInfo=this.DlinkListInfo;
      //做一下选框的处理
      if (this.formData.listValueCheck) {
        this.checkboxOptions.forEach((ele) => {
          if (this.formData.listValueCheck.length > 0) {
            if (this.formData.listValueCheck.indexOf(ele.value) >= 0) {
              this.formData[ele.value] = true;
            } else {
              this.formData[ele.value] = false;
            }
          } else {
            this.formData[ele.value] = false;
          }
        });
      }
      // if (this.formData.defaultValue) {
      //   this.$delete(this.formData, "defaultValue");
      // }
      // if (this.formData.description) {
      //   this.$delete(this.formData, "description");
      // }

      this.formData.dataType = this.entryMethodList;
      this.$emit("closedia", this.title, this.formData, this.dataObj.index);
    },
    // 保存
    handleOk() {
      this.$refs.elForm.validate((valid) => {
        if (valid) {
          if (this.title === "编辑") {
            this.handleAdd();
          } else {
            if (this.tableData.length == 0) {
              this.handleAdd();
            } else {
              const fieldNameArr = [];
              const fieldLabelArr = [];
              this.tableData.forEach((item) => {
                fieldNameArr.push(item.fieldName);
                fieldLabelArr.push(item.fieldLabel);
              });
              //如果字段名重复或字段标识重复
              if (
                fieldNameArr.indexOf(this.formData.fieldName) != -1 ||
                fieldLabelArr.indexOf(this.formData.fieldLabel) != -1
              ) {
                if (fieldNameArr.indexOf(this.formData.fieldName) != -1) {
                  return this.$message.error(
                    this.formData.fieldName + " 字段名重复"
                  );
                } else {
                  return this.$message.error(
                    this.formData.fieldLabel + " 字段标识重复"
                  );
                }
              } else {
                //不重复
                this.handleAdd();
              }
            }
          }
        }
      });
      // debugger;
    },
    handleClose() {
      this.$emit("closedia");
    },
    //获取字段类型枚举
    getFieldTypeName() {
      getFieldType()
        .then((response) => {
          this.field103Options = response.data;
        })
        .catch((err) => {
          console.log(err);
          // this.$message.error(err.message);
        });
    },
    //获取精度
    getPrecision() {
      getPrecisionNum()
        .then((response) => {
          this.precisionList = response.data;
        })
        .catch((err) => {
          // this.$message.error(err.message);
          console.log(err);
        });
    },
    //第一个输入框
    getOtherInfo() {
      let requTWO = {
        metadataId: this.metadataId,
      };
      getMetadataList(requTWO)
        .then((response) => {
          this.OtherList = response.data;
          if (this.title == "添加") {
            this.firstValueSelect = this.formData.metadataId;
          }
        })
        .catch((err) => {
          // this.$message.error(err.message);
          console.log(err);
        });
    },
    //第-个选择框选择以后第二个
    selectChanged() {
      this.formData.fetchFrom = "";
      // console.log(this.OtherList,this.firstValueSelect,'this.OtherList');
      this.OtherList.forEach((element) => {
        if (element.id == this.firstValueSelect) {
          this.formData.metadataName = element.label;
        }
      });
      let queryOtherName = {
        metadataId: this.firstValueSelect,
      };
      getMetadataFieldNameList(queryOtherName)
        .then((response) => {
          this.ContinueSelection = response.data;
        })
        .catch((err) => {
          // this.$message.error(err.message);
          console.log(err);
        });
    },
    //选择的时候变为空
    selectChoose(val) {
      console.log(val, "change");
    },
    //删除
    remove(item) {
      var index = this.formData.select.indexOf(item);
      if (index !== -1) {
        this.formData.select.splice(index, 1);
      }
    },
    //添加
    add() {
      this.formData.select.push({
        value: "",
      });
    },
  },
};
</script>

<style lang="scss" scoped>
@import "~@/assets/styles/mixin.scss";
@import "~@/assets/styles/variables.scss";
::v-deep .el-dialog__body {
  padding: 0px 20px;
  max-height: 850px;
  overflow: auto;
}
::v-deep .el-dialog__header {
  padding: 0;
  height: 70px;
  line-height: 70px;
  background-color: $labelColor;
  position: relative;
}
::v-deep .el-dialog__title {
  color: #fff;
  margin-left: 30px;
  font-size: 18px;
}
::v-deep .el-dialog__headerbtn {
  top: 50%;
  right: 20px;
  transform: translate(0, -50%);
  z-index: 2;
}
::v-deep .el-dialog__close {
  border: 1px solid #fff;
  color: #fff;
  border-radius: 50%;
}
::v-deep .el-checkbox__input .is-checked {
  color: $labelColor !important;
}
::v-deep .is-checked .el-checkbox__inner {
  background-color: $labelColor !important;
}
::v-deep .is-checked .el-checkbox__inner::after {
  height: 13px;
  width: 7px;
  border-color: #fff;
  top: -1px;
}

.lodingBar {
  position: absolute;
  height: 70px;
  top: 0;
  right: 0;
  z-index: 1;
}
.dialogForm {
  padding: 25px 40px;
}
.el-form-item {
  width: 100%;
  margin-bottom: 18px;
}
.inconstyle {
  font-size: 12px;
  color: $labelColor;
  width: 8%;
}
.addDownstyle {
  margin-bottom: 15px !important;
}
// .addinconstyle{
// margin-left: 100px;
// }
.selectBox {
  width: 100%;
  height: auto;
  max-height: 150px;
  overflow-y: scroll;
  overflow-x: hidden;
}
.dialog-footer {
  text-align: center;
  padding-bottom: 20px;
}
.bootonclose {
  width: 122px;
  height: 40px;
  background-color: #fff;
  border: 1px solid #e8eaec;
  border-radius: 4px;
  font-size: 16px;
  color: $labelColor;
}
.bootonok {
  width: 122px;
  height: 40px;
  background-color: $labelColor;
  border-radius: 4px;
  color: #fff;
  margin-left: 20px;
  font-size: 16px;
}
::v-deep .newcheckout .el-radio__inner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
}
::v-deep .newcheckout .el-radio__input.is-checked .el-radio__inner {
  background-color: #fff !important;
  border-color: $labelColor !important ;
}
::v-deep .newcheckout .el-radio__input.is-checked .el-radio__inner:hover {
  border-color: $labelColor !important ;
}
::v-deep .newcheckout .el-radio__inner::after {
  width: 10px;
  height: 10px;
  background: $labelColor !important;
}
::v-deep .newcheckout .el-radio__input.is-checked + .el-radio__label {
  color: $labelColor !important;
}
// class="labelStyle">{{ it
// class="modelnameStyle">
// class="nameStyle">名称:<
//从其他元数据选择
.firstValueStyle span {
  float: left;
}
.firstValueStyle .labelStyle {
  display: inline-block;
  width: 40%;
}
.firstValueStyle .modelnameStyle {
  display: inline-block;
  width: 35%;
  white-space: nowrap; /*内容超宽后禁止换行显示*/
  overflow: hidden; /*超出部分隐藏*/
  text-overflow: ellipsis; /*文字超出部分以省略号显示*/
}
.firstValueStyle .nameStyle {
  display: inline-block;
  width: 25%;
  white-space: nowrap; /*内容超宽后禁止换行显示*/
  overflow: hidden; /*超出部分隐藏*/
  text-overflow: ellipsis; /*文字超出部分以省略号显示*/
}
</style>
<style scoped>
/deep/.el-checkbox {
  margin-right: 14px;
}
/deep/.selectBox .el-form-item__content {
  margin-left: 0px !important;
}
</style>
